package com.itheima.config;

import org.springframework.context.annotation.Configuration;

import javax.servlet.http.HttpSession;
import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig;

@Configuration
public class GetHttpSessionConfig extends ServerEndpointConfig.Configurator {
    //编写配置类，用于获取 HttpSession 对象
    @Override
    public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
        //获取httpsession对象
        HttpSession httpSession =(HttpSession) request.getHttpSession();

        //将httpsession对象保存起来，保存到ServerEndpointConfig中
        sec.getUserProperties().put(HttpSession.class.getName(),httpSession);
    }
}
